package com.yangzehan.workbench.Controller;

import com.yangzehan.domaim.User;
import com.yangzehan.utils.DateTimeUtil;
import com.yangzehan.utils.UUIDUtil;
import com.yangzehan.workbench.domain.Activity;
import com.yangzehan.workbench.domain.ActivityRemark;
import com.yangzehan.workbench.service.ActivityRemarkService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ActivityRemarkController {
    @Resource
    private ActivityRemarkService service;
    @ResponseBody
    @RequestMapping(value = "/getRemarks.do")
    public List<ActivityRemark>geRemark(HttpServletRequest request){
        String  id = request.getParameter("id");
        List<ActivityRemark> list=service.getRemark(id);
        return list;
    }
   @ResponseBody
    @RequestMapping(value = "/deleteRemark.do")
    public boolean delete(HttpServletRequest request){
        boolean n;
        String id=request.getParameter("id");
       n= service.delete(id);


        return n;
   }
   @ResponseBody
    @RequestMapping(value = "/savaRemark.do")
    public Map<String, Object> savaRemark(HttpServletRequest request,ActivityRemark activityRemark){

       System.out.println(activityRemark);
        String id= UUIDUtil.getUUID();
        String createTime= DateTimeUtil.getSysTime();
        String createBy=( (User)request.getSession().getAttribute("user")).getName();
        String editFlag="0";
        activityRemark.setEditFlag(editFlag);
        activityRemark.setCreateBy(createBy);
        activityRemark.setId(id);
        activityRemark.setCreateTime(createTime);
       System.out.println(activityRemark);
        boolean n =service.savaRemark(activityRemark);
       System.out.println(n);
        Map<String, Object> map=new HashMap<>();
        map.put("key",n);
        map.put("ar",activityRemark);
        return map;

   }
   @ResponseBody
    @RequestMapping(value = "/updateRemark.do")
    public Map<String, Object>updateRemark(HttpServletRequest request,ActivityRemark activityRemark){
        Map<String, Object> map=new HashMap<>();
      String editBy = ((User)request.getSession().getAttribute("user")).getName();
      String editTime=DateTimeUtil.getSysTime();
      String editFlag="1";
      activityRemark.setEditBy(editBy);
      activityRemark.setEditFlag(editFlag);
      activityRemark.setEditTime(editTime);
     boolean n= service.updateRemark(activityRemark);
      map.put("key",n);
      map.put("ar",activityRemark);




        return map;
   }

}
